home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / mac / h10srcst.hqx / Source / HyperHell Source / App NCSA TektoPICT / tekmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-29  |  25.9 KB  |  1,099 lines

  1. /*
  2.  * File Sample.c
  3.  *
  4.  * Copyright Apple Computer, Inc. 1985-1987
  5.  * All rights reserved.
  6.  *
  7.  * Sample application in C
  8.  *
  9.  *    This sample displays a fixed sized window in which the user can
  10.  *    enter and edit text.  The style and layout of the procedures
  11.  *    reflects C programming style, and differs somewhat from the
  12.  *    simple example Pascal program outlined in "Inside Macintosh".
  13.  *
  14.  *    The C Sample includes a few minor additions to the Pascal sample:
  15.  *    [1] About Sample... dialog box supported.
  16.  *    [2] The I-Beam cursor is set when inside the window
  17.  *    [3] Various bugs are fixed concerning the current port, cut/copy/paste
  18.  *        to/from the clipboard, a few random crasher bugs
  19.  *    [4] Segmentation is demonstrated
  20.  */
  21.  
  22. #include    <types.h>
  23. #include    <quickdraw.h>
  24. #include    <toolutils.h>
  25. #include    <fonts.h>
  26. #include    <events.h>
  27. #include    <windows.h>
  28. #include    <dialogs.h>
  29. #include    <menus.h>
  30. #include    <desk.h>
  31. #include    <textedit.h>
  32. #include    <scrap.h>
  33. #include    <segload.h>
  34. #include     <osutils.h>
  35. #include    <files.h>
  36. #include     <toolutils.h>
  37. #include    <packages.h>
  38. #include    <resources.h>
  39.  
  40. extern _DataInit();
  41.  
  42. /*
  43.  * Resource ID constants.
  44.  */
  45. #define    appleID            128             /* This is a resource ID */
  46. #define    fileID             129             /* ditto */
  47. #define    editID             130             /* ditto */
  48. #define optionsID        131
  49.  
  50. #define    appleMenu        0                /* MyMenus[] array indexes */
  51. #define    aboutMeCommand    1
  52.  
  53. #define    fileMenu        1
  54. #define OpenTek            1
  55. #define CreatePICT        2
  56. #define    quitCommand     4
  57.  
  58. #define    editMenu        2
  59. #define    undoCommand     1
  60. #define    cutCommand        3
  61. #define    copyCommand     4
  62. #define    pasteCommand    5
  63. #define    clearCommand    6
  64.  
  65. #define optionsMenu        3
  66. #define Draw_All        1
  67. #define Select_Dialog    2
  68. #define File_Dialog        3
  69. #define Frame_Dialog     4
  70.  
  71. #define menuCount        4
  72.  
  73. /*
  74.  * For the one and only text window
  75.  */
  76. #define windowID        128
  77. /*
  78.  * For the About Sample... DLOG
  79.  */
  80. #define    aboutMeDLOG        128
  81. #define    okButton        1
  82. #define    authorItem        2            /* For SetIText */
  83. #define    languageItem    3            /* For SetIText */
  84.  
  85. /*
  86.  * C programs typically use macros for simple expressions which
  87.  * must be function calls in Pascal.  Here are a couple of examples:
  88.  */
  89.  
  90. /*
  91.  * Inline SetRect() macro, efficient when (rectp) is a constant.
  92.  * Must not be used if (rectp) has side effects.
  93.  *
  94.  * We could do an InsetRect() macro in a similar vein.
  95.  */
  96. #define SETRECT(rectp, _left, _top, _right, _bottom)    \
  97.     (rectp)->left = (_left), (rectp)->top = (_top),     \
  98.     (rectp)->right = (_right), (rectp)->bottom = (_bottom)
  99.  
  100. /*
  101.  * HIWORD and LOWORD macros, for readability.
  102.  */
  103. #define HIWORD(aLong)        (((aLong) >> 16) & 0xFFFF)
  104. #define LOWORD(aLong)        ((aLong) & 0xFFFF)
  105.  
  106. /*
  107.  * Global Data objects, used by routines external to main().
  108.  */
  109. MenuHandle        MyMenus[menuCount];     /* The menu handles */
  110. Boolean         DoneFlag;                /* Becomes TRUE when File/Quit chosen */
  111. TEHandle        TextH;                    /* The TextEdit handle */
  112.  
  113.  
  114.  
  115. int main()
  116. {
  117.     Rect                    screenRect;
  118.     Rect                    dragRect;
  119.     Rect                    txRect;
  120.     Point                    mousePt;
  121.     CursHandle                ibeamHdl;
  122.     EventRecord             myEvent;
  123.     WindowPtr                theActiveWindow;
  124.     WindowPtr                whichWindow;
  125.     register    WindowPtr    myWindow;            /* Referenced often */
  126.     WindowRecord            wRecord;
  127.     extern void             setupMenus();
  128.     extern void             doCommand();
  129.     extern void                Opening_Dialog();
  130.  
  131.     /*
  132.      * Initialization traps
  133.      */
  134.     UnloadSeg(_DataInit);
  135.     InitGraf(&qd.thePort);
  136.     InitFonts();
  137.     FlushEvents(everyEvent, 0);
  138.     InitWindows();
  139.     InitMenus();
  140.     TEInit();
  141.     InitDialogs(nil);
  142.     InitCursor();
  143.     
  144.     MaxApplZone();
  145.     MoreMasters();        /* I want memory, */
  146.     MoreMasters();        /* Lots of Memory, */
  147.     MoreMasters();        /* I want ApplHeap, and SysHeap, and more */
  148.     MoreMasters();                         
  149.  
  150.     /*
  151.      * setupMenus is execute-once code, so we can unload it now.
  152.      */
  153.     setupMenus();            /* Local procedure, below */
  154.     UnloadSeg(setupMenus);
  155.     /* Call for opening dialog */
  156.     Opening_Dialog();
  157.     /*
  158.      * Calculate the drag rectangle in advance.
  159.      * This will be used when dragging a window frame around.
  160.      * It constrains the area to within 4 pixels from the screen edge
  161.      * and below the menu bar, which is 20 pixels high.
  162.      */
  163.     screenRect = qd.screenBits.bounds;
  164.     SETRECT(&dragRect, 4, 20 + 4, screenRect.right-4, screenRect.bottom-4);
  165.     /*
  166.      * Create our one and only window from the WIND resource.
  167.      * If the WIND resource isn't there, we die.
  168.      */
  169.     myWindow = GetNewWindow(windowID, &wRecord, (WindowPtr) -1);
  170.     SetPort(myWindow);
  171.     /*
  172.      * Create a TextEdit record with the destRect and viewRect set
  173.      * to my window's portRect (offset by 4 pixels on the left and right
  174.      * sides so that text doesn't jam up against the window frame).
  175.      */
  176.     txRect = myWindow->portRect;
  177.     InsetRect(&txRect, 4, 0);
  178.     TextH = TENew(&txRect, &txRect);    /* Not growable, so destRect == viewRect */
  179.  
  180.     ibeamHdl = GetCursor(iBeamCursor);        /* Grab this for use later */
  181.     /*
  182.      * Ready to go.
  183.      * Start with a clean event slate, and cycle the main event loop
  184.      * until the File/Quit menu item sets DoneFlag.
  185.      *
  186.      * It would not be good practice for the doCommand() routine to
  187.      * simply ExitToShell() when it saw the QuitItem -- to ensure
  188.      * orderly shutdown, satellite routines should set global state,
  189.      * and let the main event loop handle program control.
  190.      */
  191.     DoneFlag = false;
  192.     for ( ;; ) {
  193.         if (DoneFlag) {
  194.             /*
  195.              * Quit has been requested, by the File/Quit menu, or perhaps
  196.              * by a fatal error somewhere else (missing resource, etc).
  197.              * Here we could put up a Save Changes? DLOG, which would also
  198.              * allow the Cancel buttion to set DoneFlag to false.
  199.              */
  200.             break;        /* from main event loop */
  201.         }
  202.         /*
  203.          * Main Event tasks:
  204.          */
  205.         SystemTask();
  206.         theActiveWindow = FrontWindow();        /* Used often, avoid repeated calls */
  207.         /*
  208.          * Things to do on each pass throught the event loop
  209.          * when we are the active window:
  210.          *        [1] Track the mouse, and set the cursor appropriately:
  211.          *            (IBeam if in content region, Arrow if outside)
  212.          *        [2] TEIdle our textedit window, so the insertion bar blinks.
  213.          */
  214.         /*
  215.          * Handle the next event.
  216.          * In a more complex application, this switch statement
  217.          * would probably call satellite routines to handle the
  218.          * major cases (mouseDown, keyDown, etc), but our actions
  219.          * are simple here and it suffices to perform the code in-line.
  220.          */
  221.         if (!GetNextEvent(everyEvent, &myEvent)) {
  222.             /*
  223.              * A null or system event, not for me.
  224.              * Here is a good place for heap cleanup and/or
  225.              * segment unloading if I want to.
  226.              */
  227.             continue;
  228.         }
  229.         /*
  230.          * In the unlikely case that the active desk accessory does not
  231.          * handle mouseDown, keyDown, or other events, GetNextEvent() will
  232.          * give them to us!  So before we perform actions on some events,
  233.          * we check to see that the affected window in question is really
  234.          * our window.
  235.          */
  236.         switch (myEvent.what) {
  237.             case mouseDown:
  238.                 switch (FindWindow(&myEvent.where, &whichWindow)) {
  239.                     case inSysWindow:
  240.                         SystemClick(&myEvent, whichWindow);
  241.                         break;
  242.  
  243.                     case inMenuBar:
  244.                         doCommand(MenuSelect(&myEvent.where));
  245.                         break;
  246.  
  247.                     case inDrag:
  248.                         DragWindow(whichWindow, &myEvent.where, &dragRect);
  249.                         break;
  250.  
  251.                     case inGrow:
  252.                         /* There is no grow box. (Fall through) */
  253.  
  254.                     case inContent:
  255.                         if (whichWindow != theActiveWindow) {
  256.                             SelectWindow(whichWindow);
  257.                         } else if (whichWindow == myWindow) {
  258.                             GlobalToLocal(&myEvent.where);
  259.                             TEClick(&myEvent.where, (myEvent.modifiers & shiftKey) != 0, TextH);
  260.                         }
  261.                         break;
  262.  
  263.                     default:
  264.                         break;
  265.                 }/*endsw FindWindow*/
  266.                 break;
  267.  
  268.             case keyDown:
  269.             case autoKey:
  270.                 if (myWindow == theActiveWindow) {
  271.                     if (myEvent.modifiers & cmdKey) {
  272.                         doCommand(MenuKey(myEvent.message & charCodeMask));
  273.                     } else {
  274.                         TEKey((char) (myEvent.message & charCodeMask), TextH);
  275.                     }
  276.                 }
  277.                 break;
  278.  
  279.             case activateEvt:
  280.                 if ((WindowPtr) myEvent.message == myWindow) {
  281.                     if (myEvent.modifiers & activeFlag) {
  282.                         TEActivate(TextH);
  283.                         DisableItem(MyMenus[editMenu], undoCommand);
  284.                     } else {
  285.                         TEDeactivate(TextH);
  286.                         EnableItem(MyMenus[editMenu], undoCommand);
  287.                     }
  288.                 }
  289.                 break;
  290.  
  291.             case updateEvt:
  292.                 if ((WindowPtr) myEvent.message == myWindow) {
  293.                     BeginUpdate(myWindow);
  294.                     EraseRect(&myWindow->portRect);
  295.                     TEUpdate(&myWindow->portRect, TextH);
  296.                     EndUpdate(myWindow);
  297.                 }
  298.                 break;
  299.  
  300.             default:
  301.                 break;
  302.  
  303.         }/*endsw myEvent.what*/
  304.  
  305.     }/*endfor Main Event loop*/
  306.     /*
  307.      * Cleanup here.
  308.      */
  309.     CloseWindow(myWindow);
  310.     
  311.     return 0;        /* Return from main() to allow C runtime cleanup */
  312. }
  313.  
  314. /*
  315.  * Demonstration of the segmenting facility:
  316.  *
  317.  * This code is execute-once, so we toss it in the "Initialize"
  318.  * segment so that main() can unload it after it's called.
  319.  *
  320.  * There really isn't much here, but it demonstrates the segmenting facility.
  321.  */
  322. /*
  323.  * Set the segment to Initialize.  BEWARE: leading and trailing white space
  324.  * would be part of the segment name!
  325.  */
  326. #define    __SEG__ Initialize
  327.  
  328. /*
  329.  * Set up the Apple, File, and Edit menus.
  330.  * If the MENU resources are missing, we die.
  331.  */
  332. void setupMenus()
  333. {
  334.     extern        MenuHandle    MyMenus[];
  335.     register    MenuHandle    *pMenu;
  336.  
  337.     /*
  338.      * Set up the desk accessories menu.
  339.      * The "About Sample..." item, followed by a grey line,
  340.      * is presumed to be already in the resource.  We then
  341.      * append the desk accessory names from the 'DRVR' resources.
  342.      */
  343.     MyMenus[appleMenu] = GetMenu(appleID);
  344.     AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
  345.     /*
  346.      * Now the File and Edit menus.
  347.      */
  348.     MyMenus[fileMenu] = GetMenu(fileID);
  349.     MyMenus[editMenu] = GetMenu(editID);
  350.     MyMenus[optionsMenu] = GetMenu(optionsID);
  351.     /*
  352.      * Now insert all of the application menus in the menu bar.
  353.      *
  354.      * "Real" C programmers never use array indexes
  355.      * unless they're constants :-)
  356.      */
  357.     for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
  358.         InsertMenu(*pMenu, 0);
  359.     }
  360.  
  361.     DrawMenuBar();
  362.  
  363.     return;
  364. }
  365.  
  366. /*
  367.  * Back to the Main segment.
  368.  */
  369. #define    __SEG__ Main
  370.  
  371. /*
  372.  * Display the Sample Application dialog.
  373.  * We insert two static text items in the DLOG:
  374.  *        The author name
  375.  *        The source language
  376.  * Then wait until the OK button is clicked before returning.
  377.  */
  378. void showAboutMeDialog()
  379. {
  380.     GrafPtr     savePort;
  381.     DialogPtr    theDialog;
  382.     short        itemType;
  383.     Handle        itemHdl;
  384.     Rect        itemRect;
  385.     short        itemHit;
  386.  
  387.     GetPort(&savePort);
  388.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  389.     SetPort(theDialog);
  390.  
  391.     do {
  392.         ModalDialog(nil, &itemHit);
  393.     } while (itemHit != okButton);
  394.  
  395.     CloseDialog(theDialog);
  396.  
  397.     SetPort(savePort);
  398.     return;
  399. }
  400. /*
  401.  * Process mouse clicks in menu bar
  402.  */
  403. void doCommand(mResult)
  404.     long    mResult;
  405. {
  406.     int                 theMenu, theItem;
  407.     char                daName[256];
  408.     GrafPtr             savePort;
  409.     extern MenuHandle    MyMenus[];
  410.     extern Boolean        DoneFlag;
  411.     extern TEHandle     TextH;
  412.     extern void         showAboutMeDialog();
  413.     extern void            Frame_Select_Dialog();
  414.     extern void            Show_Info_Dialog2();
  415.     extern void            FrameMag_Dialog();
  416.     extern                 Tek_Draw_All();
  417.  
  418.  
  419.     theItem = LOWORD(mResult);
  420.     theMenu = HIWORD(mResult);        /* This is the resource ID */
  421.  
  422.     switch (theMenu) {
  423.         case appleID:
  424.             if (theItem == aboutMeCommand) {
  425.                 showAboutMeDialog();
  426.             } else {
  427.                 GetItem(MyMenus[appleMenu], theItem, daName);
  428.                 GetPort(&savePort);
  429.                 (void) OpenDeskAcc(daName);
  430.                 SetPort(savePort);
  431.             }
  432.             break;
  433.  
  434.         case fileID:
  435.             switch (theItem) 
  436.             {
  437.                 case OpenTek:
  438.                     Tek_File_Open();
  439.                     break;
  440.                 
  441.                 case CreatePICT:
  442.                     PICT_File_Open();
  443.                     break;
  444.                     
  445.                 case quitCommand:
  446.                     DoneFlag = true;            /* Request exit */
  447.                     break;
  448.                 default:
  449.                     break;
  450.             }
  451.             break;
  452.  
  453.         case editID:
  454.             /*
  455.              * If this is for a 'standard' edit item,
  456.              * run it through SystemEdit first.
  457.              * SystemEdit will return FALSE if it's not a system window.
  458.              */
  459.             if ((theItem <= clearCommand) && SystemEdit(theItem-1)) {
  460.                 break;
  461.             }
  462.             /*
  463.              * Otherwise, it's my window.
  464.              * Handle Cut/Copy/Paste properly
  465.              * between the TEScrap and the Clipboard.
  466.              */
  467.             switch (theItem) {
  468.                 case undoCommand:
  469.                     /* can't undo */
  470.                     break;
  471.                 case cutCommand:
  472.                 case copyCommand:
  473.                     if (theItem == cutCommand) {
  474.                         TECut(TextH);
  475.                     } else {
  476.                         TECopy(TextH);
  477.                     }
  478.                     ZeroScrap();
  479.                     TEToScrap();
  480.                     break;
  481.                 case pasteCommand:
  482.                     TEFromScrap();
  483.                     TEPaste(TextH);
  484.                     break;
  485.                 case clearCommand:
  486.                     TEDelete(TextH);
  487.                     break;
  488.                 default:
  489.                     break;
  490.             } /*endsw theItem*/
  491.             break;
  492.         
  493.     case optionsID:
  494.             switch (theItem) 
  495.             {
  496.                 case Draw_All:
  497.                     Tek_Draw_All();                /* Draw all frames */
  498.                     break;
  499.  
  500.                 case Select_Dialog:
  501.                     Frame_Select_Dialog();
  502.                     break;
  503.                     
  504.                 case File_Dialog:
  505.                     Show_Info_Dialog2();
  506.                     break;
  507.  
  508.                 case Frame_Dialog:
  509.                     FrameMag_Dialog();
  510.                     break;
  511.  
  512.                 default:
  513.                     break;
  514.             }
  515.             
  516.             break;
  517.  
  518.         default:
  519.             break;
  520.  
  521.     }/*endsw theMenu*/
  522.  
  523.     HiliteMenu(0);
  524.  
  525.     return;
  526. }
  527.  
  528.  
  529. /****************************************************************************************/
  530. /*  NCSA Tek_To_PICT Main Routines:  Here are the subroutines added onto a simple Mac 
  531.     window application to draw Tek4010 applications.  The Tek drawing is done using
  532.     the NCSA Telnet 4010 Tektronix code written by A. Porter and G. Paulsen.  Those
  533.     subroutines are contained elsewhere.  This code drives the opening of Tek4010 files
  534.     and writing those pictures as PICT resource files so that the HyperCard Scientific Animation
  535.     Tool can import the frames easily.  Hopefully, placing a Tek 4105 driver in here won't
  536.     be too painful.  This code was written by Lou Wicker with lots of help from Tim
  537.     Krauskopf.  If you find something weird, stupid, or sloppy, blame Lou because this 
  538.     is the first Mac code he ever wrote.  Have a nice day.  
  539.     
  540.                 Yours Truly,
  541.                             Lou Wicker
  542. */
  543.  
  544. #include "stdio.h"
  545.  
  546. #define ESC 27
  547. #define FF  12
  548. #define x0 0
  549. #define y0 0
  550. #define xSize 360
  551. #define ySize 270
  552. #define upperSize 125            /* Largest magnification allowed (in percent) */
  553. #define lowerSize 50            /* Smallest magnification allowed (in percent) */
  554.  
  555.  
  556.  
  557. /* Global Variables defined for the program....some are for convience, others needed */
  558.  
  559. PicHandle RGtoPICT();                   /* Convert Drawings to PICT's */
  560.  
  561. FILE *fp;                            /* File pointer to tektronix file */
  562.  
  563. int Null_Screen;                    /* Null Screen descriptor */
  564.  
  565. Rect theScreen;                        /* Screen Rect */
  566.  
  567. int Resource_File_No;                /* Resource file number for PICT's */
  568.  
  569. static int PICT_Count = 1000;        /* Numbers for the PICT's */
  570.  
  571. int PICT_File_Flag = 0;                /* PICT File Flag to tell whether a PICT file is open */
  572.  
  573. Point Dialog_Position = {150,150};    /* Position for the Dialog Boxes */
  574.                 
  575. long Filetype[4] = {'TEXT', 'TEXT', 'TEXT', 'TEXT' }; 
  576.                                     /* File types to look for */
  577.                                     
  578. char Tek_File[255] = '', PICT_File[255]='';    /* File names of input and output files */
  579.  
  580. int SkipFrame=0;                    /* How many frames to skip for in file (0=noSkip) */
  581. int StartFrame=0;                    /* Where to start in the file (0=Start At Beginning */
  582.  
  583. static int xFrame_Size = 360;        /* X Size of drawn frame */
  584. static int yFrame_Size = 290;        /* Y size of drawn frame */
  585. static int Frame_Mag = 100;            /* Magnification factor (in percent!) */
  586.             
  587. /*    End Global Variable Section */
  588.  
  589. Tek_File_Open()        /* Opens up the Tek 4010 file to read in */
  590.  
  591. {
  592.     SFReply reply;
  593.     static Boolean open_flag = false;
  594.     
  595. /* Get the Filename for the Tektronix file to read in */
  596.  
  597.     if( fp != NULL ) fclose(fp);
  598.  
  599.     SFGetFile(&Dialog_Position, "\Open File", 0L, 1, Filetype, 0L, &reply);
  600.     
  601.         if( !reply.good ) return(-1);
  602.         SetVol( 0L, reply.vRefNum );
  603.         ptoc(&reply.fName);
  604.         strcpy(Tek_File,&reply.fName);
  605.     
  606.         fp = fopen(&reply.fName,"r");    /* Open the Input file, get the file pointer */
  607.         rewind(fp);                        /* Rewind the file */
  608.         PICT_File_Flag = 0;
  609.     
  610. /* Initialize the Tektronix Graphics Package here! */
  611.     
  612.         if( !open_flag ) 
  613.         {
  614.         VGinit();                        /* Initialize the graphics */
  615.         Null_Screen=VGnewwin(0);        /* "Null_Screen" is the place for the drawing */
  616.         open_flag = true;
  617.         xFrame_Size = x0 + Frame_Mag * xSize / 100;
  618.         yFrame_Size = y0 + Frame_Mag * ySize / 100;
  619.         }
  620.     
  621. }                        /* END PICT_Open_File */
  622.  
  623. PICT_File_Open()        /* Opens a file which will contain the PICT resources */
  624.  
  625. {
  626.     SFReply reply;
  627.     int beep;
  628.     
  629. /* First, check whether a PICT file is open....if it is...then close it */
  630.  
  631.     if( PICT_File_Flag != 0 )  CloseResFile(Resource_File_No);
  632.  
  633. /* Get the filename for the PICT file */
  634.  
  635.     SFPutFile(&Dialog_Position, "\PICT Filename?", "\PICT.Movie", 0L, &reply);
  636.     
  637.         if( !reply.good ) return(-1);
  638.         SetVol(0L, reply.vRefNum);
  639.  
  640.         ptoc(&reply.fName);
  641.         strcpy(PICT_File,&reply.fName);
  642.         
  643. /* In case it exists, delete the file first */    
  644.     FSDelete(&reply.fName,reply.vRefNum);
  645.     
  646. /* Obtain the resource file number and store it in the Resource_File_No. */
  647.     CreateResFile(&reply.fName);
  648.     Resource_File_No = OpenResFile(&reply.fName);
  649.  
  650.     PICT_File_Flag = 1;
  651.     PICT_Count = 1000;
  652.     return(0);
  653.     
  654. }                        /* END PICT_Open_File */
  655.  
  656.  
  657. Tek_Draw_All()            /* Tek_Draw_All is a control subroutine which call Tek_Draw_Frame */
  658.  
  659. {
  660.     int flag = 0, reset_flag=0;
  661.     EventRecord theEvent;
  662.  
  663. /* Check to see if the user has open up the needed files */
  664.  
  665.     if (fp == NULL) 
  666.         {
  667.         OpenTek_Alert();
  668.         return(-1);
  669.         }
  670. /* Just in case we are making more than one movie from a file, rewind */        
  671.     rewind(fp);                    
  672.         
  673.     if( PICT_File_Flag == 0 ) 
  674.         {
  675.         OpenPICT_Alert();
  676.         return(-1);
  677.         }
  678.  
  679.     
  680. /* Before we start tell the User what files he/she is reading and writing from */
  681.  
  682.     reset_flag = Show_Info_Dialog1();
  683.     if( reset_flag == -1 ) return(0);
  684.  
  685.     Tek_Skip_Frame(StartFrame);    /* Set the Start position in the File */
  686.  
  687.         while( flag == 0 )
  688.             {
  689.                 flag = Tek_Draw_Frame();
  690.                 Tek_Skip_Frame(SkipFrame);    /* Skip over the number of frames */
  691.                 
  692.                 if(GetNextEvent(keyDownMask,&theEvent) ) 
  693.                 {
  694.                 if( (char)(theEvent.message & charCodeMask) == '.' ) return;
  695.                 } 
  696.             }
  697. }                        /* END Tek_Draw_All */
  698.  
  699.  
  700. Tek_Skip_Frame(Fcount)        /* Tek_Skip_Frame skips over frames in the Tek file */
  701. int Fcount;
  702. {
  703.     int buff, count=0;
  704.     char buff1, buff2;
  705.     
  706.     if( Fcount == 0 ) return;
  707.         
  708. /* Check to see if the user has open up the needed files */
  709.  
  710.     if (fp == NULL) Tek_File_Open();
  711.     
  712. /* Start reading in the Tek stream */
  713.     
  714.     if (fp != NULL) 
  715.     {
  716.         while ( count < Fcount )
  717.             {
  718.             
  719.                 buff = fgetc(fp);
  720.                 buff1 = buff;
  721.                 
  722.                 if( buff1 == FF && buff2 == ESC ) count ++;
  723.                 if( buff1 == EOF) return;
  724.                 
  725.                 buff2 = buff1;
  726.             }
  727.     }
  728. }
  729.  
  730. Tek_Draw_Frame()        /* Tek_Draw_Frame draws one picture at a time */
  731. {
  732.     char buff1, buff2; int buff;
  733.  
  734. /* Start reading in the Tek stream */
  735.     
  736.     if (fp != NULL) 
  737.     {
  738.         while ( 1 )
  739.             {
  740.     
  741.                 buff = fgetc(fp);
  742.                 buff1 = buff;
  743.                 
  744.                 if( buff == EOF ) 
  745.                     {
  746.                         EraseRect(&theScreen);        /* Erase the screen before redraw new pic */
  747.                         RGtoPICT(Null_Screen);
  748.                         VGwrite(Null_Screen,ESC,1);
  749.                         VGwrite(Null_Screen,FF,1);
  750.                         return(-1);
  751.                     }
  752.  
  753.                 if( buff1 == FF && buff2 == ESC ) 
  754.                     {
  755.                         EraseRect(&theScreen);        /* Erase the screen before redraw new pic */
  756.                         RGtoPICT(Null_Screen);
  757.                         VGwrite(Null_Screen,&buff1,1);
  758.                         return(0);
  759.                     }
  760.                      
  761.                 VGwrite(Null_Screen, &buff1, 1);
  762.                 buff2 = buff1;
  763.             }
  764.     }
  765.         
  766. }                            /* END Tek_Draw_Frame() */
  767.  
  768. PicHandle RGtoPICT(i)        /* RGtoPICT copies the drawn picture to the screen */
  769. int i;
  770. {
  771.     int j;
  772.     PicHandle thePicture;
  773.     
  774.     SetRect(&theScreen,x0,y0,xFrame_Size,yFrame_Size);/* Set bounds on the graphics rectangle */
  775.     j=VGnewwin(3);                        /* Where is that window I can draw to? */
  776.     RGMPsize(&theScreen);                /* I don't know...yet! */
  777.     ClipRect(&theScreen);                 /* Sets the clipping in theScreen */
  778.     ShowPen();                            /* Show me what you are doing with that nasty pen */
  779.     VGpage(j);
  780.     thePicture=OpenPicture(&theScreen);    /* Open up a place for me to draw to */
  781.     VGredraw(i,j);                        /* Draw that beast! from Null_Screen to thePicture */
  782.     ClosePicture();                        /* Stop saving stuff for picture */
  783.  
  784.      AddResource(thePicture,'PICT',PICT_Count++,"HYPER.PICT");
  785.     UpdateResFile(Resource_File_No);    /* update resource file with the PICT */
  786.     
  787.     VGclose(j);                            /* Don't kill the screen here, go back to main */
  788.     HidePen();                            /* Ok, you can hide the pen for a while */
  789.     EraseRect(&theScreen);                /* Erase Picture */
  790.     ReleaseResource(thePicture);
  791. }
  792.  
  793. void Frame_Select_Dialog()
  794.  
  795. {
  796.     GrafPtr     dPort;
  797.     DialogPtr    theDialog;
  798.     short        itemType;
  799.     Handle        itemHdl;
  800.     Rect        itemRect;
  801.     short        itemHit;
  802.     char        dtext[255];
  803.     Ptr            dStorage;
  804.     
  805.     static int dialogID = 2112;
  806.     int dOK = 1, dSkipFrame=2, dStartFrame=5, dCancel=6;
  807.  
  808.     GetPort(&dPort);
  809.     theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
  810.     SetPort(theDialog);    
  811.     
  812.     GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
  813.     sprintf(dtext, "%d", SkipFrame);
  814.     SetIText(itemHdl, dtext);
  815.     SelIText(theDialog, dSkipFrame, 0, 32767);
  816.  
  817.     
  818.     GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
  819.     sprintf(dtext, "%d", StartFrame);
  820.     SetIText(itemHdl, dtext);
  821. /*    SelIText(theDialog, dStartFrame, 0, 32767); */
  822.  
  823.  
  824.     do
  825.     {
  826.         ModalDialog(nil, &itemHit);
  827.             if( itemHit == dCancel) 
  828.             {
  829.             DisposDialog(theDialog);
  830.             SetPort(dPort);
  831.             return;
  832.             }
  833.  
  834.     }
  835.     while ( itemHit != dOK ); 
  836.  
  837.     GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
  838.     GetIText(itemHdl, dtext);
  839.     SkipFrame = atoi(dtext);
  840.     
  841.     GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
  842.     GetIText(itemHdl, dtext);
  843.     StartFrame = atoi(dtext);
  844.  
  845.     DisposDialog(theDialog);
  846.     
  847.     SetPort(dPort);
  848.     return;
  849. }
  850.  
  851. Show_Info_Dialog1()
  852. {
  853.     GrafPtr     dPort;
  854.     DialogPtr    theDialog;
  855.     short        itemType;
  856.     Handle        itemHdl;
  857.     Rect        itemRect;
  858.     short        itemHit;
  859.     char        dtext[255];
  860.     Ptr            dStorage;
  861.     
  862.     static int dialogID = 2113;
  863.     int dOK = 1, dTek_File=3, dPICT_File=5, dCancel=6, dSkipFrame=9, dStartFrame=10, dFrameMag=14;
  864.  
  865.     GetPort(&dPort);
  866.     theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
  867.     SetPort(theDialog);    
  868.  
  869. /* Tell them what Tek 4010 File they are reading */    
  870.     GetDItem(theDialog, dTek_File, &itemType, &itemHdl, &itemRect);
  871.     sprintf(dtext, "%c%s%c", '"',Tek_File,'"');
  872.     SetIText(itemHdl, dtext);
  873.  
  874. /* Tell them what PICT File they are Writing To */    
  875.     GetDItem(theDialog, dPICT_File, &itemType, &itemHdl, &itemRect);
  876.     sprintf(dtext, "%c%s%c", '"',PICT_File,'"');
  877.     SetIText(itemHdl, dtext);
  878.  
  879. /* Tell them what the frame skip interval is */
  880.     GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
  881.     sprintf(dtext, "%d", SkipFrame);
  882.     SetIText(itemHdl, dtext);
  883.  
  884. /* Tell them what the frame start position is */
  885.     GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
  886.     sprintf(dtext, "%d", StartFrame);
  887.     SetIText(itemHdl, dtext);
  888.  
  889. /* Tell them what the frame magnification is */
  890.     GetDItem(theDialog, dFrameMag, &itemType, &itemHdl, &itemRect);
  891.     sprintf(dtext, "%d%c", Frame_Mag,'%');
  892.     SetIText(itemHdl, dtext);
  893.  
  894.     do
  895.     {
  896.         ModalDialog(nil, &itemHit);
  897.         if( itemHit == dCancel) 
  898.         {
  899.         DisposDialog(theDialog);
  900.         SetPort(dPort);
  901.         return(-1);
  902.         }
  903.     }
  904.     while ( itemHit != dOK ); 
  905.  
  906.     DisposDialog(theDialog);
  907.     
  908.     SetPort(dPort);
  909.     return(0);
  910. }
  911.  
  912. void Show_Info_Dialog2()
  913. {
  914.     GrafPtr     dPort;
  915.     DialogPtr    theDialog;
  916.     short        itemType;
  917.     Handle        itemHdl;
  918.     Rect        itemRect;
  919.     short        itemHit;
  920.     char        dtext[255];
  921.     Ptr            dStorage;
  922.     
  923.     static int dialogID = 2213;
  924.     int dOK = 1,dTek_File=3,dPICT_File=5,dSkipFrame=9,dStartFrame=11, dFrameMag=13;
  925.  
  926.     GetPort(&dPort);
  927.     theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
  928.     SetPort(theDialog);    
  929.  
  930. /* Tell them what Tek 4010 File they are reading */    
  931.     GetDItem(theDialog, dTek_File, &itemType, &itemHdl, &itemRect);
  932.     sprintf(dtext, "%c%s%c", '"',Tek_File,'"');
  933.     SetIText(itemHdl, dtext);
  934.  
  935. /* Tell them what PICT File they are Writing To */    
  936.     GetDItem(theDialog, dPICT_File, &itemType, &itemHdl, &itemRect);
  937.     sprintf(dtext, "%c%s%c", '"',PICT_File,'"');
  938.     SetIText(itemHdl, dtext);
  939.  
  940. /* Tell them what the frame skip interval is */
  941.     GetDItem(theDialog, dSkipFrame, &itemType, &itemHdl, &itemRect);
  942.     sprintf(dtext, "%d", SkipFrame);
  943.     SetIText(itemHdl, dtext);
  944.  
  945. /* Tell them what the frame start position is */
  946.     GetDItem(theDialog, dStartFrame, &itemType, &itemHdl, &itemRect);
  947.     sprintf(dtext, "%d", StartFrame);
  948.     SetIText(itemHdl, dtext);
  949.     
  950. /* Tell them what the frame magnification is */
  951.     GetDItem(theDialog, dFrameMag, &itemType, &itemHdl, &itemRect);
  952.     sprintf(dtext, "%d%c", Frame_Mag,'%');
  953.     SetIText(itemHdl, dtext);
  954.  
  955.     do 
  956.     {
  957.         ModalDialog(nil, &itemHit);
  958.     } 
  959.     while (itemHit != dOK);
  960.  
  961.     DisposDialog(theDialog);
  962.     
  963.     SetPort(dPort);
  964. }
  965.  
  966. void FrameMag_Dialog()
  967.  
  968. {
  969.     GrafPtr     dPort;
  970.     DialogPtr    theDialog;
  971.     short        itemType;
  972.     Handle        itemHdl;
  973.     Rect        itemRect;
  974.     short        itemHit;
  975.     char        dtext[255];
  976.     Ptr            dStorage;
  977.     
  978.     static int dialogID = 2114;
  979.     int dOK = 1, dFrameSize=3, dCancel=2;
  980.  
  981.     GetPort(&dPort);
  982.     theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
  983.     SetPort(theDialog);    
  984.  
  985. /* Set the current frame magnification in the dialog box */    
  986.     GetDItem(theDialog, dFrameSize, &itemType, &itemHdl, &itemRect);
  987.     sprintf(dtext, "%d", Frame_Mag);
  988.     SetIText(itemHdl, dtext);
  989.     SelIText(theDialog, dFrameSize, 0, 32767);
  990.  
  991.     do
  992.     {
  993.         ModalDialog(nil, &itemHit);
  994.         if( itemHit == dCancel) 
  995.         {
  996.         DisposDialog(theDialog);
  997.         SetPort(dPort);
  998.         return;
  999.         }
  1000.     }
  1001.     while ( itemHit != dOK ); 
  1002.  
  1003. /* User hits "OK", then get the new frame magnification factor, do the scaling and quit */
  1004.  
  1005.     GetDItem(theDialog, dFrameSize, &itemType, &itemHdl, &itemRect);
  1006.     GetIText(itemHdl, dtext);
  1007.     Frame_Mag = atoi(dtext);
  1008.     
  1009.     xFrame_Size = x0 + Frame_Mag * xSize / 100;
  1010.     yFrame_Size = y0 + Frame_Mag * ySize / 100;
  1011.  
  1012.     if( Frame_Mag > upperSize )
  1013.         {
  1014.             FrameMag_Alert();
  1015.             Frame_Mag = upperSize;
  1016.             xFrame_Size = x0 + Frame_Mag * xSize / 100;
  1017.             yFrame_Size = y0 + Frame_Mag * ySize / 100;
  1018.         }
  1019.         
  1020.     if( Frame_Mag < lowerSize ) 
  1021.         {
  1022.             FrameMag_Alert();
  1023.             Frame_Mag = lowerSize;
  1024.             xFrame_Size = x0 + Frame_Mag * xSize / 100;
  1025.             yFrame_Size = y0 + Frame_Mag * ySize / 100;
  1026.         }
  1027.  
  1028.     DisposDialog(theDialog);
  1029.     
  1030.     SetPort(dPort);
  1031.     return;
  1032. }
  1033.  
  1034.  
  1035. void Opening_Dialog()
  1036.  
  1037. {
  1038.     DialogPtr    theDialog;
  1039.     
  1040.     static int dialogID = 23737;
  1041.     long time0, time1;
  1042.  
  1043.     theDialog = GetNewDialog(dialogID, nil, (WindowPtr) -1);
  1044.  
  1045.     DrawDialog(theDialog);
  1046.     
  1047.     time0 = TickCount();
  1048.     do 
  1049.     {
  1050.     time1 = TickCount();
  1051.     } while( time1 - time0 <= 210 );
  1052.  
  1053.     DisposDialog(theDialog);
  1054.     
  1055. }
  1056.  
  1057. FrameMag_Alert()
  1058. {
  1059.     static int alertID = 3113;
  1060.     CautionAlert(alertID, 0);
  1061. }
  1062.  
  1063. OpenPICT_Alert()
  1064. {
  1065.     static int alertID = 3112;
  1066.     StopAlert(alertID, 0);
  1067. }
  1068.  
  1069. OpenTek_Alert()
  1070. {
  1071.     static int alertID = 3111;
  1072.     StopAlert(alertID, 0);
  1073. }
  1074.  
  1075. Close_Files()    /* Close_Files cleans up the file stuff */
  1076.  
  1077. {
  1078.     if( PICT_File_Flag == 1 ) CloseResFile(Resource_File_No);
  1079.     
  1080.     if( fp != NULL ) fclose(fp);
  1081. }
  1082.  
  1083.  
  1084. /* Thanks to Tim Krauskopf for this function */
  1085. ptoc(s)
  1086.     char *s;
  1087. {
  1088.     register int len;
  1089.     
  1090.     len = *s+1;
  1091.     
  1092.     while( --len ) 
  1093.     {
  1094.         *s = *(s+1);
  1095.         s++;
  1096.     }
  1097.     
  1098.     *s = '\0';
  1099. }